from tg.config import AppConfig, Bunch
import gigboard
from gigboard import model
from gigboard.lib import app_globals, helpers

class CustomConfig(AppConfig):
    
    def setup_routes(self):
        """Setup some custom TG2 routes"""
        map = Mapper(directory=config['pylons.paths']['controllers'],
                        always_scan=config['debug'])

        # Setup a default route for the error controller:
        map.connect('error/:action/:id', controller='error')
        
        #map.connect('archive/:service/:channel/:year/:month/:day',
        #            controller='archive', view='date_view',
        #            requirements=dict(year='\d{2,4}', month='\d{1,2}', day='\d{1,2}'))
        
        # Setup a default route for the root of object dispatch
        #map.connect('*url', controller='root', action='routes_placeholder')

        config['routes.map'] = map

base_config = AppConfig()
base_config.renderers = []

base_config.package = gigboard

#Set the default renderer
base_config.default_renderer = 'genshi'
base_config.renderers.append('genshi') 

#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = gigboard.model
#Configure the authentication backend
base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth = Bunch()
base_config.sa_auth.dbsession = model.DBSession
base_config.sa_auth.user_class = model.User
base_config.sa_auth.user_criterion = model.User.name
base_config.sa_auth.user_id_column = 'id'

# override this if you would like to provide a different who plugin for 
# managing login and logout of your application
base_config.sa_auth.form_plugin = None 